﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Shapes;
using System.Windows.Threading;
using System.ComponentModel;
using System.Windows.Input;
using System.Windows.Media.Animation;
using System.Windows;
using System.Collections.ObjectModel;
using OperGui.ViewModel;
using System.Windows.Controls;
using OperGui.Models;


namespace OperGui
{
    public class MainWindowViewModel : ViewModelBase
    {
        #region field
        Timecontrol _time;
        FrameworkElement _currentView;
        string _performance;
        public string NVN;
        public int listN;
    

        #endregion
        ObservableCollection<CommandViewModel> _commands;
        #region constructor
        public MainWindowViewModel()
        {
            CurrentView = new Views.TilesView(null);
            Commands.Add(new CommandViewModel("Initial Page", new RelayCommand(e => this.ElementonViewSwitch("Initial Page"))));
            _time = new Timecontrol();
            
        }
        #endregion
        
        
        
        // 13:55
        public ObservableCollection<CommandViewModel> Commands
        {
            get
            {
                if (_commands == null)
                {
                    List<CommandViewModel> cmds = this.CreateCommands();
                    _commands = new ObservableCollection<CommandViewModel>(cmds);
                }
                return _commands;
            }
        }

     
        List<CommandViewModel> CreateCommands()
        {
            return new List<CommandViewModel>
            {
                
                   
                
            };
        }

//
      



        public Timecontrol TimeControl
        {
            get { return _time; }
        }

        public ICommand switchView
        {
            get { return new RelayCommand(OnViewSwitch) as ICommand; }
        }

        //public ICommand goZone
        //{
        //    get { return new RelayCommand(ZoneonViewSwitch) as ICommand; }
        //}

        //public ICommand goSection
        //{
        //    get { return new RelayCommand(SectiononViewSwitch) as ICommand; }
        //}



        //void ZoneonViewSwitch(object view)
        //{
        //    CurrentView = new Views.TilesView(null);

        //}

        //void SectiononViewSwitch(object view)
        //{
        //    TileView _tile = view as TileView;

        //    CurrentView = new Views.SectionView();
        //}

        void ElementonViewSwitch(string NVID)
        {

            int s = 0, N = Commands.Count;
            foreach (CommandViewModel a in Commands)
            {
                if (a.DisplayName == NVID)
                {
                    s = Commands.IndexOf(a);
                }
            }
            for (int x = N - 1; x > s; x--)
            {
                Commands.RemoveAt(x);
            }
            if (NVID == "Initial Page")
            {
                CurrentView = new Views.TilesView(null);
            }

            else
            {
                CurrentView = new Views.ElementView(NVID);
            }
        }

        void OnViewSwitch(object view)
        {
           
            if (view.ToString() == "Initial Page")
            {
               
                //Commands.Add(new CommandViewModel("Initial Page", new RelayCommand(e => this.ElementonViewSwitch("Initial Page"))));
            }
            else
            {
                Button _tile = view as Button;
                Grid _Content = _tile.Content as Grid;
                string NVID = _tile.Tag.ToString();                                                                                                                                     
               
                NVN = _Content.Name.ToString();
                if (NVN == "_CG")
                {
                    CurrentView = new Views.ElementView(NVID);
                    Commands.Add(new CommandViewModel(NVID, new RelayCommand(e => this.ElementonViewSwitch(NVID))));
                }
            }
             
       }


        public FrameworkElement CurrentView
        {
            get { return _currentView; }
            set { _currentView = value; base.OnPropertyChanged("CurrentView"); }
        }

        public string performance
        { get { return _performance; } set { _performance = value; OnPropertyChanged("performance"); } }

    }
}
